package com.fishingwithme.infrastructure.dtos.circle;

import com.fishingwithme.domain.common.Location;
import com.fishingwithme.infrastructure.utils.CommonUtils;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Data;

import java.util.List;

import static net.minidev.json.JSONArray.toJSONString;

@Data
public class CircleDto {
    private Long id;
    private String title;
    private String description;
    private Double area;
    private Double latitude;
    private Double longitude;
    private List<Location> points;
    @JsonIgnore
    private String pointsString;
    @JsonIgnore
    private String picsString;
    private String city;
    private String cityCode;
    private Boolean isActive;
    private List<String> pics;

    public CircleDto() {
    }

    public static CircleDto format(CircleDto dto) {
        dto.setPointsString(toJSONString(dto.getPoints()));
        if (dto.getPics() != null) {
            dto.setPicsString(toJSONString(dto.getPics()));
        }
        return dto;
    }

    public static CircleDto formatDtoJson(CircleDto dto) {
        dto.points = CommonUtils.convert(dto.pointsString, Location.class);
        if (dto.getPicsString() != null) {
            dto.pics = CommonUtils.convert(dto.picsString, String.class);
        }
        return dto;
    }
}
